--[[
 -- *名称:DdzAnalysisResult
 -- *描述:分析结果包装类 
 -- *版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
 -- *作者:Administrator
 -- *创建日期:2017-11-07
 -- *修改日期:2017-11-07
 ]]
local AnalyzerCounter = require(basePath.."suit/analyzercounter");
local DdzAnalysisResult = pokercore.class();

--设置元表
local mt = {}
mt.__tostring = function (t)
   return "DdzAnalysisResult [type=" .. (t.type and tostring(t.type) or "nil") .. ", weight=" .. (t.weight and tostring(t.weight) or "nil") .. "]";
end


---
 -- [ctor 默认类的构造方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function DdzAnalysisResult:ctor(...)
   --缓存类型
   self.type = nil ;
   --分析结果的代表权值，最终比较到这个权值
   self.weight = -1 ;
   --点数计数器
   self.allValueCounter = pokercore.new(AnalyzerCounter) ;
   --牌数量计数器
   self.cardNum = 0 ;
   --非癞子点数计数器
   self.noneLaziValueCounter = pokercore.new(AnalyzerCounter) ;
   --癞子点数计数器
   self.laziValueCounter = pokercore.new(AnalyzerCounter) ;
   --癞子数量计数器
   self.laziCardNum = 0 ;
   --排序
   self.sortFirstValue = -1 ;
   --王牌数量
   self.jokerCardNum = 0;
   --已经被赋值的癞子数量
   self.changedLaziCardNum = 0 ;


   local meta = getmetatable(self) or {};
   table.merge(meta,mt)
   setmetatable(self,meta)
end

function DdzAnalysisResult:getType()
	return self.type ;
end

--[[
 -- [compareTo 比较大小，-1 小于 0 等于 1大于]
 -- @DateTime 2017-11-07
 -- @param    compareTo [description]
 -- @return    [description]
 ]]
function DdzAnalysisResult:compareTo(compareTo)
	if (not compareTo or  not compareTo:getType()) then
			--print("compareTo compareTo == null || compareTo.getType() == null !!!");
			return 1;
 	elseif not self.type then
			--print("compareTo this.getType() == null !!!");
			return -1;
	else 
		-- 先比较一下权重
		local weight = self:getType():getWeight() - compareTo:getType():getWeight();
		if (weight == 0) then
			return self:doCompareTo(compareTo);
		else 
			return weight;
		end
	end
end




--[[
 -- [doCompareTo description]
 -- @DateTime 2017-11-07
 -- @param    compareTo [description]
 -- @return    [description]
 ]]
function DdzAnalysisResult:doCompareTo(compareTo)
	if (self.cardNum ~= compareTo.cardNum) then -- 长度不一致
		return -1;
	else 
		return self.weight - compareTo.weight;
	end
end

function DdzAnalysisResult:clone()
	return pokercore.clone(self);
end


---
 -- [collectNumber 收集牌信息]
 -- @DateTime 2017-11-07
 -- @param    cards [description]
 -- @param    term [description]
 -- @return    [description]
 --
function DdzAnalysisResult:collectNumber(cards,term)
	self.allValueCounter:clear();
	self.laziValueCounter:clear();
	self.jokerCardNum = 0 ;
	self.noneLaziValueCounter:clear();
	self.cardNum = cards:size();
	self.jokerCardNum = 0 ;
	self.changedLaziCardNum = 0 ;
	--print("DdzAnalysisResult:collectNumber:\n",cards or "nil");
	local laziCardNum = 0 ;
	for k,card in pairs(cards:getCardList()) do
		--print("collectNumber-card->",card)
		self.allValueCounter:addValueCount(card:getValue());
		if (card:getValue() == PokerGameConstant.RED_JOKER_SHAPE_NUM
						or card:getValue() == PokerGameConstant.BLACK_JOKER_SHAPE_NUM) then
					self.jokerCardNum = self.jokerCardNum + 1;
		end
		if card:hasNotChanged() then
			self.laziValueCounter:addValueCount(card:getValue());
			laziCardNum = laziCardNum + 1 ;
		elseif card:hasChanged() then --如果是癞子且已经赋值
			self.noneLaziValueCounter:addValueCount(card:getValue());
			self.changedLaziCardNum = self.changedLaziCardNum + 1 ;
		else
			self.noneLaziValueCounter:addValueCount(card:getValue());
		end

	end
	self.laziCardNum = laziCardNum ;
end

---
 -- [isAllCardLazi 是否所有牌都是癞子]
 -- @DateTime 2017-11-07
 -- @return   [description]
 --
function DdzAnalysisResult:isAllCardLazi()
--	return (self.cardNum - self.laziCardNum) == 0;
	return (self.laziCardNum + self.changedLaziCardNum == self.cardNum) ;
end

---
 -- [getNoneCardNum 非癞子牌数量]
 -- @DateTime 2017-11-07
 -- @return   [description]
 --
function DdzAnalysisResult:getNoneCardNum()
	return self.cardNum - self.laziCardNum;
end


--####################setter & getter###############################
function DdzAnalysisResult:getAllValueCounter()
	return self.allValueCounter ;
end

function DdzAnalysisResult:getNoneLaziValueCounter()
	return self.noneLaziValueCounter ;
end

function DdzAnalysisResult:getLaziValueCounter()
	return self.laziValueCounter ;
end


function DdzAnalysisResult:setType(rType)
   self.type = rType ;
end

function DdzAnalysisResult:getWeight()
	return self.weight ;
end

function DdzAnalysisResult:setWeight(weight)
	self.weight = weight ;
end

function DdzAnalysisResult:getCardNum()
	return self.cardNum ;
end

function DdzAnalysisResult:getJokerCardNum()
	return self.jokerCardNum ;
end

function DdzAnalysisResult:setJokerCardNum(jokerCardNum)
	self.jokerCardNum = jokerCardNum ;
end

function DdzAnalysisResult:setCardNum(weight)
	self.cardNum = cardNum ;
end


function DdzAnalysisResult:getLaziCardNum()
	return self.laziCardNum ;
end

function DdzAnalysisResult:setLaziCardNum(laziCardNum)
	self.laziCardNum = laziCardNum ;
end

function DdzAnalysisResult:getChangedLaziCardNum()
	return self.changedLaziCardNum ;
end

function DdzAnalysisResult:setChangedLaziCardNum(changedLaziCardNum)
	self.changedLaziCardNum = changedLaziCardNum ;
end

function DdzAnalysisResult:getSortFirstValue()
	return self.sortFirstValue;
end

function DdzAnalysisResult:setSortFirstValue(sortFirstValue)
	self.sortFirstValue = sortFirstValue;
end

function DdzAnalysisResult:getLaziValueCounter()
	return self.laziValueCounter;
end

--[[
 -- 判断是否要移除
 -- @DateTime 2017-11-16
 -- @param    compareTo [description]
 -- @return    [description]
 ]]
function DdzAnalysisResult:compareToFlip(compareTo)
	--print("DdzAnalysisResult:compareToFlip")
	local typeWeight = self.type:getWeight() - compareTo.type:getWeight();
	if typeWeight < 0 then
    	return true 
    elseif typeWeight > 0 then
    	return false ;
    end
	local typedis = self.type:getType() - compareTo.type:getType();
	if typedis ~= 0 then
		return true ;
	end
	local lenDis = self.cardNum - compareTo.cardNum ;
	if lenDis ~= 0 then
		return true ;
	end
	local weight = self:getWeight() - compareTo:getWeight();
	if weight>0 then
		return false ;
	end
	return true ;
end

function DdzAnalysisResult:compareToSort(compareTo)
   	if (not compareTo or  not compareTo:getType()) then
			print("compareTo compareTo == null || compareTo.getType() == null !!!");
			return false;
 	elseif not self.type then
			print("compareTo this.getType() == null !!!");
			return true;
	else 
		-- 先比较一下权重
		local typedis = self.type:getType() - compareTo.type:getType();
		if typedis>0 then
			return false ;
		elseif typedis < 0 then
			return true ;
		end
		-- 在比较一下张数
		local lenDis = self.cardNum - compareTo.cardNum ;
		if lenDis > 0 then
			return false ;
		elseif lenDis < 0 then
			return true ;
		end
		--在比较权重
		local weight = self:getWeight() - compareTo:getWeight();
		--print("weight->",weight);
		if (weight == 0) then
		
		else 
			if weight>0 then
				return false;
			else
				return true;
			end
		end
	end
end

---
 -- [dtor 默认类的销毁方法]
 -- @DateTime 2017-09-20
 -- @param     [description]
 -- @return    [description]
 --
function DdzAnalysisResult:dtor(...)
  
end


return DdzAnalysisResult;

